package com.groupbuying.sysconfig.intercepter;




import com.groupbuying.sysconfig.constants.WechatAliCommonConstans;
import com.groupbuying.sysconfig.domain.SysconfigPlatformInfoDO;

import java.util.HashMap;
import java.util.Map;

public class ConfigContextHandler {
    public static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<Map<String, Object>>();

    public static void set(String key, Object value) {
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocal.set(map);
        }
        map.put(key, value);
    }

    public static Object get(String key) {
        Map<String, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocal.set(map);
        }
        return map.get(key);
    }

    public static void remove() {
        threadLocal.remove();
    }

    public static void setSysconfigInfo(SysconfigPlatformInfoDO sysconfig){
        set(WechatAliCommonConstans.CONFIG_CACHE_KEY,sysconfig);
    }
    public static SysconfigPlatformInfoDO getSysconfigInfo(){
        return (SysconfigPlatformInfoDO) get(WechatAliCommonConstans.CONFIG_CACHE_KEY);
    }




}
